import 'package:ez_ic_led/bluetooth/send_data.dart';
import 'package:ez_ic_led/commont/bg_bar_view.dart';
import 'package:ez_ic_led/commont/slider_item.dart';
import 'package:ez_ic_led/tool/assets.dart';
import 'package:flutter/material.dart';
import 'package:flutter_kit_audio/flutter_kit_audio.dart';

import '../commont/custom_pickerview.dart';

class VoiceView extends StatefulWidget {
  const VoiceView({super.key});

  @override
  State<VoiceView> createState() => _VoiceViewState();
}

class _VoiceViewState extends State<VoiceView> {
  List<List<String>> _items = [];
  double sensitivityValue = 90;
  int? modeIndex;
  @override
  void initState() {
    _items.add(List.generate(255, ($0) => 'MODE${$0 + 1}'));
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return BgBarView(
        barTag: assets.Voice_control_btn,
        showLine: false,
        child: Container(
          color: Colors.transparent,
          child: Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Flexible(
                  child: Material(
                color: Colors.transparent,
                child: Center(
                  child: Container(
                    width: 50,
                    height: 90,
                    child: InkWell(
                      highlightColor: Colors.white.withOpacity(0.4),
                      splashColor: Colors.white.withOpacity(0.4),
                      borderRadius: BorderRadius.circular(25),
                      onTap: () {
                        setState(() => mic_on = !mic_on);
                        if (mic_on) {
                          SendData.send('声控模式', modeIndex ?? 1);
                        }
                      },
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Image.asset(mic_on ? assets.mic_on : assets.mic_off, width: 20, height: 40),
                          Text('Mic', style: TextStyle(fontSize: 12, color: mic_on ? Color_btn_hight : Colors.white)),
                        ],
                      ),
                    ),
                  ),
                ),
              )),
              Flexible(
                  child: CustomPickerview(
                      items: _items,
                      onChanged: (p0, p1) {
                        modeIndex = p1 + 1;
                        FlutterKitAudio.customSound(soundType: FlutterKitAudioCustomSoundType.click18);
                        if (mic_on) {
                          SendData.send('声控模式', modeIndex);
                        }
                      })),
              Flexible(
                  child: SliderItem(
                name: 'Sensitivity',
                min: 1,
                max: 100,
                value: sensitivityValue,
                nameDown: false,
                onChange: (p0) {
                  sensitivityValue = p0;
                  if (mic_on) {
                    SendData.send('声控灵敏度', sensitivityValue.toInt());
                  }
                },
              )),
            ],
          ),
        ));
  }
}
